﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "xpushbuttonfunction.h"
#include "xpushbuttonfourarithmetic.h"

#include "xlabelpixmap.h"
#include "xlabelstring.h"
#include "xscale.h"
#include "xscalechart.h"
#include "xpushbuttonfunction.h"
#include "xpushbutton.h"

#include "xnamespace.h"

#include <QRadialGradient>
#include <QColor>
#include <QtCharts/QPieSeries>
#include <QtCharts/QChartView>
#include <QComboBox>


using namespace xvs;
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ObjLib::registerObj();

    ui->comboBox3->addItem("Light", QChart::ChartThemeLight);
    ui->comboBox3->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
    ui->comboBox3->addItem("Dark", QChart::ChartThemeDark);
    ui->comboBox3->addItem("Brown Sand", QChart::ChartThemeBrownSand);
    ui->comboBox3->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
    ui->comboBox3->addItem("High Contrast", QChart::ChartThemeHighContrast);
    ui->comboBox3->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
    ui->comboBox3->addItem("Qt", QChart::ChartThemeQt);

    ui->comboBox3->setCurrentIndex(1);
    this->updateUI();

    connect(ui->comboBox3,
            static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
            this, &MainWindow::updateUI);

//    LabelString *str = new LabelString(ui->centralwidget);
//    str->setGeometry(300, 200, 200, 100);
//    str->setDisplayDefault(false);
//    str->setDisplayString("NBjckavcacvbkbbqkacb");
//    str->setMargin(5);

//    QFont D = str->font();
//    D.setBold(true);
//    D.setPointSize(30);
//    str->setFont(D);

//    LabelPixmap *pix = new LabelPixmap(ui->centralwidget);
//    QPixmap map = QPixmap("C:/Users/X-SIGHT/Desktop/7830fc00b67f0362778f549358c8824.jpg");
//    pix->setGeometry(500, 500, 400, 300);
//    pix->setMargin(5);
//    pix->setBorderWidth(10);

//    pix->setPixmap(map);

//    XPushButton *button = new XPushButton(ui->centralwidget);;
//    button->setGeometry(600, 600, 100, 50);
//    connect(button, SIGNAL(pressed(bool)), this, SLOT(set(bool)));
//    XScale *scale = new XScale(ui->centralwidget);
//    scale->setGeometry(500, 700, 500, 50);
//    scale->setPrecision(2);
//    scale->setMainScaleNumber(3);
//    scale->setSubScaleNumber(15);
//    scale->setMainScaleColor(Qt::blue);
//    scale->setBaseScaleColor(Qt::green);
//    scale->setUnitString("赵亚楠");
//    scale->setUnitStringColor(QColor(139, 137, 137));
//    scale->setScaleValueColor(Qt::red);
//    scale->setScaleValueReverseOrder(false);
//    scale->setScaleDirection(Face_UP);
//    scale->setBorderColor(Qt::black);
//    scale->setMargin(5);

    connect(ui->RColor, SIGNAL(valueChanged(int)), this, SLOT(RColor_valuechanged(int)));
    connect(ui->GColor, SIGNAL(valueChanged(int)), this, SLOT(GColor_valuechanged(int)));
    connect(ui->BColor, SIGNAL(valueChanged(int)), this, SLOT(BColor_valuechanged(int)));

//    XScaleChart *scaleChart = new XScaleChart(ui->centralwidget);
//    scaleChart->setGeometry(200, 200, 500, 100);
//    scaleChart->setScaleDirection(Face_UP);
//    scaleChart->setPrecision(0);
//    scaleChart->setMinimumRange(0);
//    scaleChart->setMaximumRange(100);
//    scaleChart->setMainScaleNumber(11);
//    scaleChart->setSubScaleNumber(4);
////    scaleChart->setMainScaleColor(Qt::blue);
////    scaleChart->setBaseScaleColor(Qt::blue);
//    scaleChart->setCurrentValue(60);
////    scaleChart->setCurrentValueStringColor(Qt::red);
//    scaleChart->setUnitString("KM");
//    scaleChart->setUnitStringColor(QColor(139, 137, 137));
//    scaleChart->setScaleValueColor(Qt::black);
//    scaleChart->setScaleValueReverseOrder(false);
//    scaleChart->setBorderColor(Qt::transparent);
//    scaleChart->setMargin(5);
//    scaleChart->setScaleChartTitle("NB");
//    scaleChart->setScaleChartTitleColor(Qt::blue);

//    scaleChart->setWarningValue(90);
//    scaleChart->setScaleChartBarColor(QColor(10, 120, 250));
//    scaleChart->setScaleChartBarBgColor(Qt::transparent);
//    scaleChart->setScaleChartTitleEnable(false);

//    XLabelString *labelString = new XLabelString(ui->centralwidget);
//    labelString->setDisplayDefault(false);
//    labelString->setDisplayString("老天爷你的灿灿");
//    labelString->setGeometry(200, 200, 100, 50);

//    XLabelPixmap *labelPixmap = new XLabelPixmap(ui->centralwidget);
//    QPixmap map = QPixmap("C:/Users/X-SIGHT/Desktop/7830fc00b67f0362778f549358c8824.jpg");
//    labelPixmap->setGeometry(400, 400, 100, 50);
//    labelPixmap->setMargin(5);
//    labelPixmap->setBorderWidth(10);


//    QSize labelPixmapSize = labelPixmap->size();
//    QPixmap pixmap = map.scaled(labelPixmapSize, Qt::IgnoreAspectRatio);
//    labelPixmap->setPixmap(pixmap);

    pushButtonFunctionA = new XPushButtonFunction(ui->centralwidget);
    pushButtonFunctionA->setGeometry(600, 600, 100, 50);
    pushButtonFunctionA->setStyleSheet("XPushButtonFunction{"
                                       "background-color: rgb(50,197,100);"
                                       "color: black;"
                                       "border-radius: 10px;"
                                       "border-top: 1px groove gray;"
                                       "border-left: 1px groove gray;"
                                       "border-right: 3px groove gray;"
                                       "border-bottom: 3px groove gray;"
                                       "border-style: outset;"
                                       "}"
                                       ""
                                       "XPushButtonFunction:hover{"
                                       "background-color: rgb(212,12,24);"
                                       "color: black;"
                                       "border-radius: 10px;"
                                       "border-top: 1px groove gray;"
                                       "border-left: 1px groove gray;"
                                       "border-right: 3px groove gray;"
                                       "border-bottom: 3px groove gray;"
                                       "border-style: outset;"
                                       "}"
                                       ""
                                       "XPushButtonFunction:pressed{"
                                       "background-color: rgb(122,100,205);"
                                       "color: black;"
                                       "border-radius: 10px;"
                                       "border-top: 1px groove black;"
                                       "border-left: 1px groove black;"
                                       "border-right: 1px groove black;"
                                       "border-bottom: 1px groove black;"
                                       "border-style: inset;"
                                       "padding-left: 3px;"
                                       "padding-top: 3px;"
                                       "}");

    coilA = new XCoil(ui->centralwidget);
    coilA->setDeviceType(PLC);
    coilA->setDeviceNumber(9);
    coilA->setObjectType(C);
    coilA->setObjectNumber(1);
    coilA->setCoilValue(false);

//    coilB = new XCoil(ui->centralwidget);
//    coilB->setDeviceType(PLC);
//    coilB->setDeviceNumber(10);
//    coilB->setObjectType(X);
//    coilB->setObjectNumber(22);
//    coilB->setCoilValue(false);

//    XFunction xFunctionA(coilA);
//    func = &XFunction::setCoil;
//    pushButtonFunctionA->insertFunction(PressInstance, xFunctionA, func);

//    coilC = new XCoil(ui->centralwidget);
//    coilC->setCoilValue(true);
//    coilD = new XCoil(ui->centralwidget);
//    coilD->setCoilValue(false);
//    coilE = new XCoil(ui->centralwidget);
//    coilE->setCoilValue(true);
//    coilF = new XCoil(ui->centralwidget);
//    coilF->setCoilValue(false);

////    XFunction xFunctionC(coilC);
////    func = &XFunction::reverseCoil;
////    pushButtonFunctionA->insertFunction(PressStatus, xFunctionC, func);

////    XFunction xFunctionD(coilD);
////    func = &XFunction::resetCoil;
////    pushButtonFunctionA->insertFunction(ReleaseStatus, xFunctionD, func);

//    XFunction xFunctionF(coilF);
//    func = &XFunction::resetCoil;
//    pushButtonFunctionA->insertFunction(PressInstance, xFunctionF, func);

//    XFunction xFunctionE(coilE);
//    func = &XFunction::reverseCoil;
//    pushButtonFunctionA->insertFunction(PressInstance, xFunctionE, func);

//    XFunction xFunctionB(coilA, coilB);
//    func = &XFunction::copyCoil;
//    pushButtonFunctionA->insertFunction(PressInstance, xFunctionB, func);

//    registerA = new XRegister(ui->centralwidget);
//    pushButtonFourArithmetic = new XPushButtonFourArithmetic(ui->centralwidget);
//    pushButtonFourArithmetic->setResultRegister(registerA);
//    pushButtonFourArithmetic->setLeftOperandConstant(4);
//    pushButtonFourArithmetic->setRightOperandConstant(2);
//    pushButtonFourArithmetic->setArithmeticType(Division);
//    XFunction xFunctionG(pushButtonFourArithmetic);
//    func = &XFunction::fourArithmetic;
//    pushButtonFunctionA->insertFunction(PressInstance, xFunctionG, func);

//    connect(ui->delete_2, &QPushButton::pressed, this, [=](){
//        int a = ui->index->text().toInt();
//        pushButtonFunctionA->ceshiDelete(a);
//    });
//    connect(ui->pushButton_3, &QPushButton::pressed, this, [=](){
//        int a = ui->index_2->text().toInt();
//        pushButtonFunctionA->ceshiMoveup(a);
//    });
//    connect(ui->pushButton_4, &QPushButton::pressed, this, [=](){
//        int a = ui->index_3->text().toInt();
//        pushButtonFunctionA->ceshiMovedown(a);
//    });


//    registerB = new XRegister(ui->centralwidget);
//    registerB->setRegisterValue(1000);
//    QList<XRegister *> listA;
//    listA.append(registerA);
//    listA.append(registerB);

//    registerC = new XRegister(ui->centralwidget);
//    registerD = new XRegister(ui->centralwidget);
//    QList<XRegister *> listB;
//    listB.append(registerC);
//    listB.append(registerD);

//    XFunction xFunctionH(listA, listB);
//    func = &XFunction::copyRegisterBlock;
//    pushButtonFunctionA->insertFunction(PressInstance, xFunctionH, func);


//    QList<XRegister *> listC;
//    listC.append(registerB);
//    listC.append(registerA);

//    QList<XRegister *> listD;
//    listD.append(registerC);
//    listD.append(registerD);

//    XFunction xFunctionI(listC, listD);
//    func = &XFunction::copyRegisterBlock;
//    pushButtonFunctionA->insertFunction(PressInstance, xFunctionI, func);

    timer = new QTimer(this);   //初始化一个定时器。
    connect(timer, &QTimer::timeout, this, [=](){
        ui->label->setText(QString::number(coilA->getCoilValue()));
//        ui->label_2->setText(QString(coilB->getCoilValue()));
//        ui->label_4->setText(QString::number(coilC->getCoilValue()));
//        ui->label_3->setText(QString::number(coilD->getCoilValue()));
//        ui->label_6->setText(QString::number(coilE->getCoilValue()));
//        ui->label_5->setText(QString::number(coilF->getCoilValue()));
//        ui->label_7->setText(QString::number(registerA->getRegisterValue(), 10, 2));
//        ui->label_8->setText(QString::number(registerB->getRegisterValue(), 10, 2));
//        ui->label_9->setText(QString::number(registerC->getRegisterValue(), 10, 2));
//        ui->label_10->setText(QString::number(registerD->getRegisterValue(), 10, 2));
    });

    timer->start(0);


    pushButton = new XPushButton(ui->centralwidget);
    pushButton->setGeometry(250, 250, 150, 50);
    pushButton->setObjectXCoil(coilA);
    pushButton->setPushButtonOperate(Set_Instantaneous_On);
    pushButton->setDelayEnable(true);
    pushButton->setDelayType(Constant);
    pushButton->setDelayTimeConstant(100);

    //-------------------------------------------------------------------------------B
//    pushButtonFunctionB = new XPushButtonFunction(ui->centralwidget);
//    pushButtonFunctionB->setGeometry(300, 500, 100, 50);
//    QColor colorB(0, 255, 170);
//    pushButtonFunctionB->setBgDefaultColor(colorB);

//    XFunction xFunctionF(coilA);
//    func = &XFunction::setCoil;
//    pushButtonFunctionB->insertFunction(PressInstance, xFunctionF, func);

//    XFunction xFunctionG(coilA, coilB);
//    func = &XFunction::copyCoil;
//    pushButtonFunctionB->insertFunction(PressInstance, xFunctionG, func);

//    XFunction xFunctionH(coilC);
//    func = &XFunction::reverseCoil;
//    pushButtonFunctionB->insertFunction(PressStatus, xFunctionH, func);

//    XFunction xFunctionI(coilD);
//    func = &XFunction::resetCoil;
//    pushButtonFunctionB->insertFunction(ReleaseStatus, xFunctionI, func);

//    XFunction xFunctionN(registerA, registerB);
//    func = &XFunction::copyRegister;
//    pushButtonFunctionB->insertFunction(PressStatus, xFunctionN, func);

//    //--------------------------------------------------------------------------------C
//    pushButtonFunctionC = new XPushButtonFunction(ui->centralwidget);
//    pushButtonFunctionC->setGeometry(300, 300, 100, 100);
//    QColor colorC(255, 0, 255);
//    pushButtonFunctionC->setBgDefaultColor(colorC);
//    pushButtonFunctionC->setText("aaaa");

//    func = &XFunction::resetCoil;
//    pushButtonFunctionC->insertFunction(PressInstance, xFunctionA, func);

//    func = &XFunction::copyRegister;
//    pushButtonFunctionC->insertFunction(PressStatus, xFunctionN, func);

//    //--------------------------------------------------------------------------------D
//    pushButtonFunctionD = new XPushButtonFunction(ui->centralwidget);
//    pushButtonFunctionD->setGeometry(300, 100, 100, 20);
//    QColor colorD(10, 70, 170);
//    pushButtonFunctionD->setBgDefaultColor(colorD);

//    func = &XFunction::resetCoil;
//    pushButtonFunctionD->insertFunction(ReleaseStatus, xFunctionI, func);

//    XFunction xFunctionM(registerB, 50);
//    func = &XFunction::setRegister;
//    pushButtonFunctionD->insertFunction(PressStatus, xFunctionM, func);


    //----------------------------------------------------------------------------------F
//    m_chart = new QChart();
//    QPieSeries *series = new QPieSeries();    //连续的餅图数据
//    series->append("水果:30%", 3);    //添加标签"水果:30%" 和 百分值30%
//    series->append("零食:20%", 2);
//    series->append("主食:40%", 4);
//    series->append("其他:10%", 1);

//    series->setLabelsVisible(true);
//    series->setUseOpenGL(true);
//    series->slices().at(0)->setColor(QColor(13, 128, 217)); //设置颜色
//    series->slices().at(0)->setLabelColor(QColor(13, 128, 217));
//    series->slices().at(1)->setColor(QColor(69, 13, 217));
//    series->slices().at(1)->setLabelColor(QColor(69, 13, 217));
//    series->slices().at(2)->setColor(QColor(13, 217, 152));
//    series->slices().at(2)->setLabelColor(QColor(13, 217, 152));
//    series->slices().at(3)->setColor(QColor(13, 217, 110));
//    series->slices().at(3)->setLabelColor(QColor(13, 217, 110));

//    m_chart->setTheme(QChart::ChartThemeLight);//设置白色主题
//    m_chart->setDropShadowEnabled(true);//背景阴影
//    m_chart->addSeries(series);//添加系列到QChart上

//    m_chart->setTitleBrush(QBrush(QColor(0, 0, 255))); //设置标题Brush
//    m_chart->setTitleFont(QFont("微软雅黑"));//设置标题字体
//    m_chart->setTitle("饼状图");

//    //修改说明样式
//    m_chart->legend()->setVisible(true);
//    m_chart->legend()->setAlignment(Qt::AlignRight);//底部对齐
//    m_chart->legend()->setBackgroundVisible(true);//设置背景是否可视
//    m_chart->legend()->setAutoFillBackground(true);//设置背景自动填充
//    m_chart->legend()->setColor(QColor(222, 233, 251)); //设置颜色
//    m_chart->legend()->setLabelColor(QColor(0, 100, 255)); //设置标签颜色
//    m_chart->legend()->setMaximumHeight(150);

//    QChartView *chartView = new QChartView(m_chart);
//    chartView->setRenderHint(QPainter::Antialiasing);

//    QVBoxLayout *pVLayout = new QVBoxLayout(ui->centralwidget);
//    pVLayout->addWidget(chartView);

//    resize(960, 720);
//    //----------------------------------------------------------------------------------H
//    m_chart = new QChart();
//    //创建3个条线数据
//    QBarSet *set0 = new QBarSet("零食");
//    QBarSet *set1 = new QBarSet("水果");
//    QBarSet *set2 = new QBarSet("主食");

//    *set0 << 158 << 685 << 458 << 260 << 354;    //向零食数据添加这4个月的销售数据
//    *set1 << 350 << 725 << 602 << 523 << 458;
//    *set2 << 222 << 350 << 598 << 480 << 687;

//    set0->setLabelColor(QColor(0,0,255));       //设置条形数据颜色
//    set1->setLabelColor(QColor(0,0,255));
//    set2->setLabelColor(QColor(0,0,255));

//    QBarSeries *series = new QBarSeries();
//    series->append(set0);
//    series->append(set1);
//    series->append(set2);
//    series->setVisible(true);
//    series->setLabelsVisible(true);

//    m_chart->setTheme(QChart::ChartThemeLight);//设置白色主题
//    m_chart->setDropShadowEnabled(true);//背景阴影
//    m_chart->addSeries(series);//添加系列到QChart上

//    m_chart->setTitleBrush(QBrush(QColor(0,0,255)));//设置标题Brush
//    m_chart->setTitleFont(QFont("微软雅黑"));//设置标题字体
//    m_chart->setTitle("超市销售条形图");

//    //创建X轴和Y轴
//    QBarCategoryAxis *axisX = new QBarCategoryAxis;
//    axisX->append("一月");
//    axisX->append("二月");
//    axisX->append("三月");
//    axisX->append("四月");
//    axisX->append("五月");
//    axisX->setLabelsColor(QColor(7,28,96));

//    QValueAxis *axisY = new QValueAxis;
//    axisY->setRange(0,1000);   //改为setRange(0,1);则表示坐标为动态计算大小的
//    axisY->setTitleText("价格");
//    axisY->setLabelFormat("%d$");

//    m_chart->setAxisX(axisX,series);
//    m_chart->setAxisY(axisY,series);

//    //修改说明样式
//    m_chart->legend()->setVisible(true);
//    m_chart->legend()->setAlignment(Qt::AlignBottom);//底部对齐
//    m_chart->legend()->setBackgroundVisible(true);//设置背景是否可视
//    m_chart->legend()->setAutoFillBackground(true);//设置背景自动填充
//    m_chart->legend()->setColor(QColor(222,233,251));//设置颜色
//    m_chart->legend()->setLabelColor(QColor(0,100,255));//设置标签颜色
//    m_chart->legend()->setMaximumHeight(50);

//    QChartView *chartView = new QChartView(m_chart);
//    chartView->setRenderHint(QPainter::Antialiasing);

//    QVBoxLayout *pVLayout = new QVBoxLayout(ui->centralwidget);
//    pVLayout->addWidget(chartView);
//    resize(960, 720);

    //    //----------------------------------------------------------------------------------I
//    m_chart = new QChart();
//    QSplineSeries *series1 = new QSplineSeries();//实例化一个QLineSeries对象
//    series1->setColor(QColor(0,100,255));
//    series1->append(QPointF(0,qrand()%200)) ;
//    series1->append(QPointF(30,qrand()%200)) ;
//    series1->append(QPointF(60,qrand()%200)) ;
//    series1->append(QPointF(90,qrand()%200)) ;
//    series1->append(QPointF(120,qrand()%200)) ;
//    series1->setName("线条1");

//    series1->setVisible(true);
//    series1->setPointLabelsFormat("(@xPoint,@yPoint)");
//    series1->setPointLabelsVisible(true);

//    m_chart->setTheme(QChart::ChartThemeLight);//设置白色主题
//    m_chart->setDropShadowEnabled(true);//背景阴影    m_chart->setAutoFillBackground(true);  //设置背景自动填充
//    m_chart->addSeries(series1);//添加系列到QChart上


//    m_chart->setTitleBrush(QBrush(QColor(0,0,255)));//设置标题Brush
//    m_chart->setTitleFont(QFont("微软雅黑"));//设置标题字体
//    m_chart->setTitle("曲线图");


//    //创建X轴和Y轴
//    QValueAxis *axisX = new QValueAxis;
//    axisX->setRange(0,150);    //默认则坐标为动态计算大小的
//    axisX->setLabelFormat("%dS");
//    QValueAxis *axisY = new QValueAxis;
//    axisY->setRange(0,250);    //默认则坐标为动态计算大小的
//    axisY->setTitleText("value值");

//    m_chart->setAxisX(axisX,series1);
//    m_chart->setAxisY(axisY,series1);
//    //m_chart->createDefaultAxes();             //或者创建默认轴

//    //修改说明样式
//    m_chart->legend()->setVisible(true);
//    m_chart->legend()->setAlignment(Qt::AlignBottom);//底部对齐
//    m_chart->legend()->setBackgroundVisible(true);//设置背景是否可视
//    m_chart->legend()->setAutoFillBackground(true);//设置背景自动填充
//    m_chart->legend()->setColor(QColor(222,233,251));//设置颜色
//    m_chart->legend()->setLabelColor(QColor(0,100,255));//设置标签颜色
//    m_chart->legend()->setMaximumHeight(50);
//    QChartView *chartView = new QChartView(m_chart);
//    chartView->setRenderHint(QPainter::Antialiasing);

//    QVBoxLayout *pVLayout = new QVBoxLayout(ui->centralwidget);
//    pVLayout->addWidget(chartView);

//    resize(960, 720);

    myChart = new XStaticChart(ui->centralwidget);
    myChart->setGeometry(10, 10, 380, 250);

    Array tickLabels{"String"};
    String str1("c");
    String str2("a");
    String str3("d");
    String str4("v");
    String str5("b");
    tickLabels.Push_Back<String>(str1);
    tickLabels.Push_Back<String>(str2);
    tickLabels.Push_Back<String>(str3);
    tickLabels.Push_Back<String>(str4);
    tickLabels.Push_Back<String>(str5);
    myChart->setTickLabelType(Custom_TickLabel);
    myChart->setTickLabel(tickLabels);

    Array x{"Real"};
    Real x1 = 1;
    Real x2 = 2.1;
    Real x3 = 3;
    Real x4 = 3.5;
    Real x5 = 4;
    Real x6 = 4.7;
    Real x7 = 5.3;
    Real x8 = 6;
    Real x9 = 7;
    Real x10 = 8.5;
    Real x11 = 9;
    x.Push_Back(x1);
    x.Push_Back(x2);
    x.Push_Back(x3);
    x.Push_Back(x4);
    x.Push_Back(x5);
    x.Push_Back(x6);
    x.Push_Back(x7);
    x.Push_Back(x8);
    x.Push_Back(x9);
    x.Push_Back(x10);
    x.Push_Back(x11);
    myChart->setXArray(x);

    Array barData1{"Integer"};
    Integer a1 = 2;
    Integer a2 = 7;
    Integer a3 = 1;
    Integer a4 = 4;
    Integer a5 = 5;
    Integer a6 = 4;
    Integer a7 = 8;
    Integer a8 = 3;
    Integer a9 = 9;
    Integer a10 = 5;
    Integer a11 = 6;
    barData1.Push_Back<Integer>(a1);
    barData1.Push_Back<Integer>(a2);
    barData1.Push_Back<Integer>(a3);
    barData1.Push_Back<Integer>(a4);
    barData1.Push_Back<Integer>(a5);
    barData1.Push_Back<Integer>(a6);
    barData1.Push_Back<Integer>(a7);
    barData1.Push_Back<Integer>(a8);
    barData1.Push_Back<Integer>(a9);
    barData1.Push_Back<Integer>(a10);
    barData1.Push_Back<Integer>(a11);
    XCustomBar *bar1 = new XCustomBar(myChart);
    bar1->setValue(barData1);
    bar1->setPenColor(QColor(150, 2, 100));
    bar1->setBrushColor(QColor(170, 200, 70));
    bar1->setTextColor(Qt::red);
    bar1->setTextOffset(5);
    bar1->setTextPosition(TopInside_ValueText);
    myChart->barCharts->barList->addChart(bar1);


//    Array brushColor{"Point3D"};
//    Point3D colorbrush1(10, 250, 10);
//    Point3D colorbrush2(10, 10, 250);
//    Point3D colorbrush3(250, 10, 10);
//    Point3D colorbrush4(250, 100, 250);
//    Point3D colorbrush5(100, 200, 100);
//    brushColor.Push_Back(colorbrush1);
//    brushColor.Push_Back(colorbrush2);
//    brushColor.Push_Back(colorbrush3);
//    brushColor.Push_Back(colorbrush4);
//    brushColor.Push_Back(colorbrush5);

//    myChart->setScatterShape(QCPScatterStyle::ssSquare);
//    myChart->setValueTextPosition(None_ValueText);
//    myChart->setValueTextColor(textColor);


//    QStringList list2;
//    list2 << "None_ValueText" << "TopOutside_ValueText" << "TopInside_ValueText" << "CenterInside_ValueText" << "BottomInside_ValueText";
//    ui->comboBox2->addItems(list2);
//    ui->comboBox2->setCurrentIndex(0);

//    connect(ui->comboBox2, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),[=](int index){
//        switch(index)
//        {
//        case 0: myChart->setValueTextPosition(None_ValueText); break;
//        case 1: myChart->setValueTextPosition(TopOutside_ValueText); break;
//        case 2: myChart->setValueTextPosition(TopInside_ValueText); break;
//        case 3: myChart->setValueTextPosition(CenterInside_ValueText); break;
//        case 4: myChart->setValueTextPosition(BottomInside_ValueText); break;
//        }
//    });

//    connect(ui->scatterSize, &QSlider::valueChanged, [=](int size){
//        Integer scatterSize(size);
//        myChart->setScatterSize(scatterSize);
//    });

//    Point2D


//    connect(pushButton, &XPushButton::pressed, [=](){
//qDebug() << "触发";
//        myChart->setTickLabelType(Default_TickLabel);
//        QColor penColor1(40, 10, 200);
//        QColor brushColor1(201, 22, 78);
//        myChart->setPenColor(penColor1);
//        myChart->setBrushColor(brushColor1);
//        myChart->setSeriesType(ScatterLine_Series);
//    });

//    connect(pushButtonFunctionA, &XPushButton::pressed, [=](){
//        myChart->setTickLabelType(Custom_TickLabel);
//        QColor penColor2(200, 150, 50);
//        QColor brushColor2(100, 90, 78);
//        myChart->setPenColor(penColor2);
//        myChart->setBrushColor(brushColor2);
//        myChart->setSeriesType(Impulse_Series);
//    });
}

MainWindow::~MainWindow()
{
    delete pushButtonFunctionA;
    pushButtonFunctionA = nullptr;
//    delete pushButtonFunctionB;
//    pushButtonFunctionB = nullptr;
//    delete pushButtonFunctionC;
//    pushButtonFunctionC = nullptr;
//    delete pushButtonFunctionD;
//    pushButtonFunctionD = nullptr;

    delete coilA;
    coilA = nullptr;
//    delete coilB;
//    coilB = nullptr;
//    delete coilC;
//    coilC = nullptr;
//    delete coilD;
//    coilD = nullptr;
//    delete registerA;
//    registerA = nullptr;
//    delete registerB;
//    registerB = nullptr;

//    delete pushButtonFourArithmetic;
//    pushButtonFourArithmetic = nullptr;

    delete myChart;
    myChart = nullptr;

    func = nullptr;

    delete ui;
}

void MainWindow::RColor_valuechanged(int value)
{
    r = value;

    ui->R1->setText(QString::number(r));
    draw();
}
void MainWindow::GColor_valuechanged(int value)
{
    g = value;
    ui->G1->setText(QString::number(g));
    draw();
}
void MainWindow::BColor_valuechanged(int value)
{
    b = value;
    ui->B1->setText(QString::number(b));
    draw();
}


void MainWindow::draw()
{
    QPalette palette;
    palette.setColor(QPalette::Background, QColor(r, g, b));
    ui->labelColor->setAutoFillBackground(true);
    ui->labelColor->setPalette(palette);
}

void MainWindow::set(bool res)
{
    qDebug() << res;
}

void MainWindow::updateUI()
{
    QChart::ChartTheme theme = static_cast<QChart::ChartTheme>(
                ui->comboBox3->itemData(ui->comboBox3->currentIndex()).toInt());

//        QPalette pal = window()->palette();
        QPalette pal;
        if (theme == QChart::ChartThemeLight) {
            pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        } else if (theme == QChart::ChartThemeDark) {
            pal.setColor(QPalette::Window, QRgb(0x121218));
            pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
        } else if (theme == QChart::ChartThemeBlueCerulean) {
            pal.setColor(QPalette::Window, QRgb(0x40434a));
            pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
        } else if (theme == QChart::ChartThemeBrownSand) {
            pal.setColor(QPalette::Window, QRgb(0x9e8965));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        } else if (theme == QChart::ChartThemeBlueNcs) {
            pal.setColor(QPalette::Window, QRgb(0x018bba));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        } else if (theme == QChart::ChartThemeHighContrast) {
            pal.setColor(QPalette::Window, QRgb(0xffab03));
            pal.setColor(QPalette::WindowText, QRgb(0x181818));
        } else if (theme == QChart::ChartThemeBlueIcy) {
            pal.setColor(QPalette::Window, QRgb(0xcee7f0));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        } else {
            pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
            pal.setColor(QPalette::WindowText, QRgb(0x404044));
        }
        window()->setPalette(pal);
}
